{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e32ac820",
   "metadata": {},
   "source": [
    "## Numapy 练习题\n",
    "打印当前Numapy版本\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4a131dfa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.24.3\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "print(np.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3aaa87f",
   "metadata": {},
   "source": [
    "\n",
    "构造一个全零矩阵，并打印其占用的内存大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "58e0347d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200 bytes\n"
     ]
    }
   ],
   "source": [
    "z= np.zeros((5,5))\n",
    "print('%d bytes' %(z.size * z.itemsize))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e775df1",
   "metadata": {},
   "source": [
    "打印一个函数的帮助文档，比如numapy.add"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "79ba373b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "add(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])\n",
      "\n",
      "Add arguments element-wise.\n",
      "\n",
      "Parameters\n",
      "----------\n",
      "x1, x2 : array_like\n",
      "    The arrays to be added.\n",
      "    If ``x1.shape != x2.shape``, they must be broadcastable to a common\n",
      "    shape (which becomes the shape of the output).\n",
      "out : ndarray, None, or tuple of ndarray and None, optional\n",
      "    A location into which the result is stored. If provided, it must have\n",
      "    a shape that the inputs broadcast to. If not provided or None,\n",
      "    a freshly-allocated array is returned. A tuple (possible only as a\n",
      "    keyword argument) must have length equal to the number of outputs.\n",
      "where : array_like, optional\n",
      "    This condition is broadcast over the input. At locations where the\n",
      "    condition is True, the `out` array will be set to the ufunc result.\n",
      "    Elsewhere, the `out` array will retain its original value.\n",
      "    Note that if an uninitialized `out` array is created via the default\n",
      "    ``out=None``, locations within it where the condition is False will\n",
      "    remain uninitialized.\n",
      "**kwargs\n",
      "    For other keyword-only arguments, see the\n",
      "    :ref:`ufunc docs <ufuncs.kwargs>`.\n",
      "\n",
      "Returns\n",
      "-------\n",
      "add : ndarray or scalar\n",
      "    The sum of `x1` and `x2`, element-wise.\n",
      "    This is a scalar if both `x1` and `x2` are scalars.\n",
      "\n",
      "Notes\n",
      "-----\n",
      "Equivalent to `x1` + `x2` in terms of array broadcasting.\n",
      "\n",
      "Examples\n",
      "--------\n",
      ">>> np.add(1.0, 4.0)\n",
      "5.0\n",
      ">>> x1 = np.arange(9.0).reshape((3, 3))\n",
      ">>> x2 = np.arange(3.0)\n",
      ">>> np.add(x1, x2)\n",
      "array([[  0.,   2.,   4.],\n",
      "       [  3.,   5.,   7.],\n",
      "       [  6.,   8.,  10.]])\n",
      "\n",
      "The ``+`` operator can be used as a shorthand for ``np.add`` on ndarrays.\n",
      "\n",
      ">>> x1 = np.arange(9.0).reshape((3, 3))\n",
      ">>> x2 = np.arange(3.0)\n",
      ">>> x1 + x2\n",
      "array([[ 0.,  2.,  4.],\n",
      "       [ 3.,  5.,  7.],\n",
      "       [ 6.,  8., 10.]])\n",
      "Help on NoneType object:\n",
      "\n",
      "class NoneType(object)\n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __bool__(self, /)\n",
      " |      True if self else False\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(help(np.info(np.add)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d0acd48",
   "metadata": {},
   "source": [
    "创建一个10-49的数组，并将其倒序排列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ef742074",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33,\n",
       "       32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,\n",
       "       15, 14, 13, 12, 11, 10])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array = np.arange(10,50,1)\n",
    "tang_array = tang_array[::-1]\n",
    "tang_array"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac811009",
   "metadata": {},
   "source": [
    "找到一个数组中不为 0 的索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "99421b6c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([ 0,  1,  2,  3,  4,  8, 10], dtype=int64),)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.nonzero([1,2,3,4,5,0,0,0,1234,0,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24b0f54e",
   "metadata": {},
   "source": [
    "随机构造一个 3 * 3 矩阵，并打印其中最大与最小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "02fb6d46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.883200962778432"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array = np.random.random((3,3))\n",
    "tang_array.min()\n",
    "tang_array.max()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0cd53b81",
   "metadata": {},
   "source": [
    "构建一个 5 * 5 的矩阵，令其值都为1，并在最外层加上一圈0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "264d7781",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
       "       [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
       "       [0., 0., 1., 1., 1., 1., 1., 0., 0.],\n",
       "       [0., 0., 1., 1., 1., 1., 1., 0., 0.],\n",
       "       [0., 0., 1., 1., 1., 1., 1., 0., 0.],\n",
       "       [0., 0., 1., 1., 1., 1., 1., 0., 0.],\n",
       "       [0., 0., 1., 1., 1., 1., 1., 0., 0.],\n",
       "       [0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
       "       [0., 0., 0., 0., 0., 0., 0., 0., 0.]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array = np.ones((5,5))\n",
    "tang_array = np.pad(tang_array,pad_width=2,mode='constant',constant_values=0)\n",
    "tang_array"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7560a37",
   "metadata": {},
   "source": [
    "构建一个shape为（6,7,8）的矩阵，并找到第100个元素的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a8b60ef1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 5, 4)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unravel_index(100,(6,7,8))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0284840",
   "metadata": {},
   "source": [
    "对一个 5 * 5的矩阵做归一化操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4ff3f7cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.98533335, 0.25846697, 0.89414584, 0.60392049, 0.5726817 ],\n",
       "       [0.23472696, 0.90304327, 0.97005176, 0.52695568, 0.58847832],\n",
       "       [0.64343599, 0.        , 0.08648505, 0.83920833, 0.89935769],\n",
       "       [0.96000532, 0.43114924, 0.48603079, 0.33047836, 0.76231967],\n",
       "       [0.0016496 , 0.87171314, 1.        , 0.03848984, 0.70764766]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array = np.random.random((5,5))\n",
    "tang_max = tang_array.max()\n",
    "tang_min = tang_array.min()\n",
    "tang_array = (tang_array -tang_min)/(tang_max - tang_min)\n",
    "tang_array "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7dabe77",
   "metadata": {},
   "source": [
    "找到两个数组中相同的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "65429476",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9 1 3 4 2 0 6 4 6 3]\n",
      "[1 7 4 7 5 3 2 6 5 5]\n",
      "[1 2 3 4 6]\n"
     ]
    }
   ],
   "source": [
    "z1 = np.random.randint(0,10,10)\n",
    "z2 = np.random.randint(0,10,10)\n",
    "print(z1)\n",
    "print(z2)\n",
    "print(np.intersect1d(z1,z2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df61fae6",
   "metadata": {},
   "source": [
    "得到今天明天昨天的日期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "0c11c12b",
   "metadata": {},
   "outputs": [],
   "source": [
    "yesterday = np.datetime64('today','D') - np.timedelta64(1,'D')\n",
    "today = np.datetime64('today','D')\n",
    "\n",
    "tommorow= np.datetime64('today','D') + np.timedelta64(1,'D')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6814d8bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2025-04-09')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yesterday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "5b20ffc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2025-04-10')"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "today"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "44cd5171",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2025-04-11')"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tommorow"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3104a72",
   "metadata": {},
   "source": [
    "得到一个月中所有的天"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "62fe42d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2025-04-01', '2025-04-02', '2025-04-03', '2025-04-04',\n",
       "       '2025-04-05', '2025-04-06', '2025-04-07', '2025-04-08',\n",
       "       '2025-04-09', '2025-04-10', '2025-04-11', '2025-04-12',\n",
       "       '2025-04-13', '2025-04-14', '2025-04-15', '2025-04-16',\n",
       "       '2025-04-17', '2025-04-18', '2025-04-19', '2025-04-20',\n",
       "       '2025-04-21', '2025-04-22', '2025-04-23', '2025-04-24',\n",
       "       '2025-04-25', '2025-04-26', '2025-04-27', '2025-04-28',\n",
       "       '2025-04-29', '2025-04-30'], dtype='datetime64[D]')"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arange('2025-04','2025-05',dtype='datetime64[D]')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81df46c5",
   "metadata": {},
   "source": [
    "得到一个数的整数部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2e16f7ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6., 2., 0., 9., 7., 3., 6., 9., 6., 1.])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z = np.random.uniform(0,10,10)\n",
    "np.floor(z)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ab5353f",
   "metadata": {},
   "source": [
    "构造一个数组，让它不能被改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "0a7027e1",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "assignment destination is read-only",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[35], line 3\u001b[0m\n\u001b[0;32m      1\u001b[0m z \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros(\u001b[38;5;241m5\u001b[39m)\n\u001b[0;32m      2\u001b[0m z\u001b[38;5;241m.\u001b[39mflags\u001b[38;5;241m.\u001b[39mwriteable\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m z[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m\n",
      "\u001b[1;31mValueError\u001b[0m: assignment destination is read-only"
     ]
    }
   ],
   "source": [
    "z = np.zeros(5)\n",
    "z.flags.writeable=False\n",
    "z[0] =1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8815815b",
   "metadata": {},
   "source": [
    "打印大数据的部分值，全部值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "a374f947",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.set_printoptions(threshold=5)\n",
    "z = np.zeros((15,15))\n",
    "z"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f95a4698",
   "metadata": {},
   "source": [
    "找到一个数组中，最接近一个数的索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "3fe7176e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "57.41938482347641\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "z = np.arange(100)\n",
    "v = np.random.uniform(0,100)\n",
    "print(v)\n",
    "index = (np.abs(-v)).argmin()\n",
    "print(z[index])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f54f7ea",
   "metadata": {},
   "source": [
    "32位float类型和32位 int类型转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "cd3d18ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int32\n",
      "float32\n"
     ]
    }
   ],
   "source": [
    "z = np.arange(10,dtype=np.int32)\n",
    "print(z.dtype)\n",
    "z = z.astype(np.float32)\n",
    "print(z.dtype)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e6636d4",
   "metadata": {},
   "source": [
    "打印数组元素位置坐标与数值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "bbb4a2d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0, 0) 0\n",
      "(0, 1) 1\n",
      "(0, 2) 2\n",
      "(1, 0) 3\n",
      "(1, 1) 4\n",
      "(1, 2) 5\n",
      "(2, 0) 6\n",
      "(2, 1) 7\n",
      "(2, 2) 8\n"
     ]
    }
   ],
   "source": [
    "z = np.arange(9).reshape(3,3)\n",
    "for index,value in np.ndenumerate(z):\n",
    "    print(index,value)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a4d9c0c",
   "metadata": {},
   "source": [
    "按照数组的某一列进行排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "84e5b8cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 9 6]\n",
      " [3 9 9]\n",
      " [9 9 8]]\n",
      "[[0 9 6]\n",
      " [3 9 9]\n",
      " [9 9 8]]\n"
     ]
    }
   ],
   "source": [
    "z = np.random.randint(0,10,(3,3))\n",
    "print(z)\n",
    "print(z[z[:,1].argsort()])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebf1d408",
   "metadata": {},
   "source": [
    "统计数组当中每个数值出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "dd3d5d06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 3, 2, ..., 0, 0, 1], dtype=int64)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z = np.array([1,1,1,2,3,2,4,5,8])\n",
    "np.bincount(z)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87d2a962",
   "metadata": {},
   "source": [
    "如何对一个四维数组的最后两维来求和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "448d499f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[81 73 65 58]\n",
      " [77 79 74 80]\n",
      " [73 57 68 74]\n",
      " [87 75 80 56]]\n"
     ]
    }
   ],
   "source": [
    "z = np.random.randint(0,10,(4,4,4,4))\n",
    "res = z.sum(axis=(-2,-1))\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2a124ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "交换矩阵中的两行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "3721876c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5,  6,  7,  8,  9],\n",
       "       [ 0,  1,  2,  3,  4],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19],\n",
       "       [20, 21, 22, 23, 24]])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "z = np.arange(25).reshape(5,5)\n",
    "z[[0,1]] = z[[1,0]]\n",
    "z"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7da41903",
   "metadata": {},
   "source": [
    "找到一个数组中最常出现的数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "0db5e523",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "z = np.random.randint(0,10,50)\n",
    "print(np.bincount(z).argmax())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dfc8108c",
   "metadata": {},
   "source": [
    "快速查找TOP K"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "c589b3ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9998 9999 9997 9996 9995]\n"
     ]
    }
   ],
   "source": [
    "z = np.arange(10000)\n",
    "np.random.shuffle(z)\n",
    "n =5\n",
    "print(z[np.argpartition(-z,n)[:n]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "726e65bc",
   "metadata": {},
   "source": [
    "去掉一个数组中，所有元素都相同的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "ebcfa222",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 4],\n",
       "       [4, 1, 0],\n",
       "       [4, 0, 1],\n",
       "       [3, 1, 1],\n",
       "       [3, 1, 0],\n",
       "       [4, 3, 3],\n",
       "       [3, 2, 0],\n",
       "       [1, 3, 4],\n",
       "       [1, 4, 2],\n",
       "       [1, 3, 4]])"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# np.set_printoptions(threshold=np.nan)\n",
    "np.set_printoptions(threshold=np.inf)\n",
    "z = np.random.randint(0,5,(10,3))\n",
    "z\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "cd8b76fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\MI\\AppData\\Local\\Temp\\ipykernel_2020\\1917637520.py:1: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.\n",
      "  e = np.all(z[:,1] == z[:,:-1])\n"
     ]
    }
   ],
   "source": [
    "e = np.all(z[:,1] == z[:,:-1],axis =1)\n",
    "print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "3485c1ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1,2,3,5])\n",
    "b = np.array([1,2,3,4])\n",
    "np.all(a == b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88b2ee03",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
